/*
 * ResourceWirehouse.h
 *
 *  Created on: 18.03.2012
 *      Author: Kirill Blinov
 *      Copyright: LGPL
 */

#ifndef RESOURCEWIREHOUSE_H_
#define RESOURCEWIREHOUSE_H_

#include <string>
#include <vector>
#include <boost/unordered_map.hpp>
#include "../Visualisator/ShaderTypes.h"
#include "../Visualisator/GameObject.h"
#include "../Visualisator/CShaderConstructor.h"
#include "../BasicTypes.h"
#include "IUnit.h"
#include "CGameWorld.h"

using namespace std;

class CResourceWarehouse
{
friend class ResourceOwner;
private:
	CResourceWarehouse();
	virtual ~CResourceWarehouse();

private:
	boost::unordered_map< string, TEXTURE_DESCRIPTOR* >				  textureDescriptorSet;
	boost::unordered_map< string, CShaderConstructor* >               shaderConstructorsSet;
	GLuint                                              			  vertexArrayId;
	GAME_OBJECT*                                  			  		  guiDummyObject;

private:
	void RemoveTexureDescriptorByIterator( boost::unordered_map< string, TEXTURE_DESCRIPTOR* >::iterator &Iter );

public:
	bool AddTextureDescriptor( TEXTURE_DESCRIPTOR* Descriptor );

	/*
	 * Replaces descriptor with the same name
	 */
	bool ReplaceTexureDescriptor( TEXTURE_DESCRIPTOR* Descriptor );

	/*
	 * Fast search for descriptor with required name
	 */
	TEXTURE_DESCRIPTOR* GetTextureDescriptorByName( const string DescriptorName );

	/*
	 * Remove descriptor
	 */
	void RemoveTextureDescriptorByName( const string DescriptorName );

	/*
	 * Add a configured shader constructor to the warehouse
	 * Return false if a constructor with this name is already exists, otherwise true
	 * P.S. Now all constructors contain the same universal parameter parser...
	 */
	bool CreateShaderProgramConstructor( const string Name,
										 GLuint ProgramName,
										 std::vector<IShaderParamParser*> ParsersArray,
										 std::string LoadedShaderParameters,
										 std::vector< std::string > SortedShaderTextures );

	CShaderConstructor* GetShaderProgramConstructor( const string Name ) const;

	/*
	 * Save vertex array ID; For now use only one vertex buffer
	 */
	void SaveVertexArrayId( const GLuint ArrayID );

	/*
	 * Return saved array ID, 0 if array ID is empty
	 */
	GLuint GetVertexArrayId() const;

	/*
	 * Memorize render information of GUI dummy
	 */
	void SetGuiDummy( GAME_OBJECT* GuiDummyObject );

	/*
	 * Return information of GUI dummy
	 */
	GAME_OBJECT* GetGuiDummy() const;

	void SetActiveGameWorld( CGameWorld* GameWorld );
};

#endif /* RESOURCEWIREHOUSE_H_ */
